
import courseItem from "../../../components/new_diy/courseItem/courseItem.vue"
import { scrollMixin } from "utils/mixin";
export default {
  name:'',
  //import引入的组件需要注入到对象中才能使用
  components: {
    courseItem
  },
  mixins: [scrollMixin], //加载更多
  data() {
  return {
    lecturerId:'',
    keyword:'',
    page:1,
    isLoadMore: true,
    total_page: 0,
    details: {},
    courseList:[],
    iPnoneBottomBol: false, //是否是苹果手机
  };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    lecturerDetails() {
      $http.post("plugin.course-supply.api.lecturer.info", {id : this.lecturerId,basic_info:1}, "加载中..").then(response => {
        if (response.result == 1) {
          let res = response.data;
          let basicInfo = response.basic_info
          this.$nextTick(() => {
            this.fun.wxShare(
              "",
              { mid: this.fun.getKeyByMid() },
              {
                link: window.location.href,
                title: '课程供应链-'+basicInfo?.home.mailInfo?.name,
                imgUrl: basicInfo?.home.mailInfo?.logo_url,
                description: '课程供应链'
              }
            );
          },50);
          this.details = res;
        } else {
          this.$dialog.alert({
            message: response.msg
          });
        }
      });
    },
    getiPnoneBottom() { //检测是否为苹果手机
      let that = this;
      var userAgent = navigator.userAgent;
      var isiOS = !!userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
      isiOS?this.iPnoneBottomBol = true:this.iPnoneBottomBol = false;
    },
    getCourseList() {
      let params = {
        keyword:this.keyword,
        page: this.page,
        lecturer_id: this.lecturerId
      }
      $http.post("plugin.course-supply.api.course.index", params, "加载中..").then(response => {
        if (response.result == 1) {
          let res = response.data;
          this.isLoadMore = true;
          this.total_page = res.last_page;
          if (!this.total_page) {
            this.page = 0;
          }
          this.courseList = res.data;
        } else {
          this.page = this.page - 1;
          this.isLoadMore = false;
          this.$dialog.alert({
            message: response.msg
          });
        }
      });
    },
    //获取更多数据
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page = this.page + 1;
        let params = {
          keyword:this.keyword,
          page: this.page,
          lecturerId: this.lecturerId
        }
        $http.post("plugin.course-supply.api.course.index", params, "加载中").then(
          res => {
            this.isLoadMore = true;
            if (res.result === 1) {
              let myData = res.data.data;
              this.courseList = [...this.courseList, ...myData]; //数组拼接
            } else {
              this.page = this.page - 1;
              this.isLoadMore = false;
            }
          },
          function(response) {
            console.log("response", response);
            // error callback
          }
        );
      }
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    if(this.$route.query.lecturerId) {
      this.lecturerId = Number(this.$route.query.lecturerId);
      this.lecturerDetails();
      this.getCourseList();
    }
    this.getiPnoneBottom();
    
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
  }